package com.example.smartcity.ui.act

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.ui.setupWithNavController
import com.example.smartcity.R
import com.example.smartcity.utils.CommonUtil
import kotlinx.android.synthetic.main.activity_main.*


/**
 * @Author: Tailyou(祝文飞)
 * @CreateDate: 2021/10/7 14:55
 * @Description: 主界面
 */
class MainActivity : AppCompatActivity() {

    companion object {
        lateinit var navController: NavController
        fun switch2AllService() {
            navController.navigate(R.id.navigation_2)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        navController = findNavController(R.id.nav_host_fragment_activity_main)
        nav_view.setupWithNavController(navController)
        nav_view.setOnNavigationItemSelectedListener { item ->
            when (item.itemId) {
                R.id.navigation_1 -> {
                    tvMainTitle.text = "智慧城市"
                    navController.navigate(R.id.navigation_1)
                }
                R.id.navigation_2 -> {
                    tvMainTitle.text = "全部服务"
                    navController.navigate(R.id.navigation_2)
                }
                R.id.navigation_3 -> {
                    tvMainTitle.text = "限选主题"
                    navController.navigate(R.id.navigation_3)
                }
                R.id.navigation_4 -> {
                    tvMainTitle.text = "新闻列表"
                    navController.navigate(R.id.navigation_4)
                }
                R.id.navigation_5 -> {
                    tvMainTitle.text = "个人中心"
                    navController.navigate(R.id.navigation_5)
                }
            }
            false
        }
    }

    var tmpTime = 0L

    override fun onBackPressed() {
        if (System.currentTimeMillis() - tmpTime > 2000) {
            CommonUtil.showToast(this, "再按一次返回退出")
            tmpTime = System.currentTimeMillis()
        } else {
            finish()
        }
    }

}